package com.xdf.mcsecurity.security;

import com.xdf.mcsecurity.utils.MD5Utils;
import org.springframework.security.crypto.password.PasswordEncoder;

public class MyPasswordEncoder implements PasswordEncoder {

    private final static String SALT = "chanchaw";
    @Override
    public String encode(CharSequence charSequence) {
        return MD5Utils.encode(charSequence.toString(),SALT);
    }

    @Override
    public boolean matches(CharSequence charSequence, String s) {
        return s.equals(MD5Utils.encode(charSequence.toString(),SALT));
    }

    public static void main(String[] args) {
        String pwd = "xdf123";
        String encoded = MD5Utils.encode(pwd,SALT);
        System.out.println(MD5Utils.encode(pwd,SALT));
        System.out.println(MD5Utils.encode("xdf123",SALT));
        System.out.println(encoded.equals(MD5Utils.encode("xdf123",SALT)));
    }
}
